package com.jpz.serviceimp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jpz.bean.User;
import com.jpz.bean.UserRole;
import com.jpz.mapper.UserRoleMapper;
import com.jpz.mapper.Usermapper;
import com.jpz.service.Userservice;
@Service
@Transactional
public class Userserviceimp extends ServiceImpl<Usermapper, User> implements Userservice {
	@Autowired
	Usermapper um;
	
	@Autowired
	UserRoleMapper urm;
	

	@Override
	public boolean update(User user, Integer[] rids) {
		Integer count = um.updateById(user);
		if(count>0){
			if(rids!=null){
				urm.delete(new EntityWrapper<UserRole>().eq("sys_user_id", user.getId()));
				for (Integer sysRoleId : rids) {
					UserRole entity=new UserRole();
					entity.setSysRoleId(sysRoleId);
					entity.setSysUserId(user.getId());
					urm.insert(entity);
				}
			}
			return true;
		}
		return false;
	}
}
